package cn.dengqiang.user.controller;

import cn.dengqiang.basic.util.AjaxResult;
import cn.dengqiang.user.dto.LoginDto;
import cn.dengqiang.user.service.ILoginInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginInfoService infoService;

    @PostMapping("/account")
    public AjaxResult login(@RequestBody LoginDto loginDto){
        System.out.println(loginDto);
        try {
            return infoService.loginAccount(loginDto);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("登录失败!"+e.getMessage());
        }
    }
    @PostMapping("/wechat")
    public AjaxResult loginWechat(@RequestBody Map<String,String> params){

        try {
            return  infoService.loginWechat(params);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统错误！"+e.getMessage());
        }
    }

    @PostMapping("/binder/wechat")
    public AjaxResult binderWechat(@RequestBody Map<String,String> params){

        try {
            return  infoService.binderWechat(params);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统错误！"+e.getMessage());
        }
    }
}
